package com.atguigu.srb.core.controller.api;


import com.alibaba.fastjson.JSON;
import com.atguigu.srb.common.result.Result;
import com.atguigu.srb.core.hfb.RequestHelper;
import com.atguigu.srb.core.pojo.entity.UserBind;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.service.UserBindService;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.Wrapper;
import java.util.Map;

/**
 * <p>
 * 用户绑定表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-03-25
 */
@RestController
@RequestMapping("/api/core/userBind")
@Slf4j
public class ApiUserBindController {
    @Resource
    UserInfoService userInfoService;

    @Resource
    UserBindService userBindService;

    @ApiOperation("用户绑定")
    @PostMapping("/bind")
    public Result bindHfb(
            @RequestHeader(value = "token", required = false) String token,
            @RequestBody UserBind userBind
            ){
        //将数据整理成表单数据，给hfb
        String formStr = userBindService.bindHfb(token, userBind);
        return Result.ok().data("form", formStr);
    }

    @ApiOperation("hfb用户绑定成功的异步回调")
    @PostMapping("/notify")
    public String hfbNotyfy(
            HttpServletRequest request
    ){
        return userInfoService.hfbNotify(request);
    }
}